<script setup lang='ts'>
import { ref, reactive,computed } from 'vue'
import { useRoute,useRouter } from 'vue-router'
import { HomeFilled, RefreshRight,Tools, ArrowDown } from '@element-plus/icons-vue'

// 定义变量
// 路由
const route = useRoute()
const router = useRouter()

// Dialog弹出框
const userInfoVisible = ref(false)
const passwordVisible = ref(false)

// 密码信息
const formLabelAlign = reactive({
  userName: 'admin',
  currentPassword: '',
  newPassword: ''
})
// 输入框规则
const rules = reactive({
  userName: [
    { required: true, message: '请输入用户名', trigger: 'blur' }
  ],
  currentPassword: [
    { required: true, message: '请输入当前密码', trigger: 'blur' }
  ],
  newPassword: [
    { required: true, message: '请输入新密码', trigger: 'blur' }
  ]
})

// 定义函数
const breadcrumb = computed(() => {
  return route.matched
})
console.log(breadcrumb)

// 切换主题
const selectTheme = (num:number) => {
  console.log('选择的主题------->',num)
}

</script>

<template>
  <div class="menu-head-main-box">
    <div class="left-box">
      <div class="logo-box" />
      <div class="breadcrumb-box">
        <div>
          <el-breadcrumb separator=">">
            <template
              v-for="(item, index) in breadcrumb"
              :key="index"
            >
              <el-breadcrumb-item v-if="item.path !== '/menu'">
                {{ item.meta?.title }}
              </el-breadcrumb-item>
            </template>
          </el-breadcrumb>
        </div>
      </div>
    </div>
    <div class="operate-btn-box">
      <div class="to-home-page">
        <el-tooltip
          class="box-item"
          effect="light"
          content="首页"
          placement="top"
        >
          <HomeFilled
            style="height: 30px;"
            @click="router.push('/homePage')"
          />
        </el-tooltip>
      </div>
      <div class="refresh-btn">
        <el-tooltip
          class="box-item"
          effect="light"
          content="刷新"
          placement="top"
        >
          <RefreshRight
            style="height: 30px;"
            @click="router.go(0)"
          />
        </el-tooltip>
      </div>
      <div class="select-theme">
        <el-tooltip
          class="box-item"
          effect="light"
          placement="top"
        >
          <Tools style="height: 30px;" />
          <template #content> 
            <div class="theme-box">
              <div
                class="white-theme"
                @click="selectTheme(0)"
              >
                白色
              </div>
              <div
                class="black-theme"
                @click="selectTheme(1)"
              >
                黑色
              </div>
              <div
                class="blue-theme"
                @click="selectTheme(2)"
              >
                蓝色
              </div>
            </div>
          </template>
        </el-tooltip>
      </div>
      <div class="sign-in">
        签到
      </div>
      <div class="sign-out">
        签退
      </div>
      <div class="user-name">
        <el-tooltip
          class="box-item"
          effect="light"
          placement="top"
        >
          admin
         
          <template #content> 
            <div class="user-box">
              <div
                class="user-info"
                @click="userInfoVisible = true"
              >
                个人资料
              </div>
              <div
                class="sign-out"
                @click="passwordVisible = true"
              >
                修改密码
              </div>
              <div
                class="update-password"
                @click="selectTheme(2)"
              >
                退出登录
              </div>
            </div>
          </template>
        </el-tooltip>
        <ArrowDown style="height: 16px;margin-left: 3px;" />
      </div>
    </div>
  </div>
  <el-dialog
    v-model="userInfoVisible"
    title="用户信息"
    width="960px"
  >
    <div id="userInfoDialog">
      <div class="left-box">
        <div>用户名：{{ 'wpn' }}</div>
        <div>备注：{{ '11111' }}</div>
      </div>
      <div class="middle-box">
        <div>手机号：{{ '10086' }}</div>
        <div>联系地址：{{ '龙域中心' }}</div>
      </div>
      <div class="right-box">
        <div>居住地：{{ '昌平' }}</div>
      </div>
    </div>
    <template #footer>
      <span class="dialog-footer">
        <el-button
          type="primary"
          @click="userInfoVisible = false"
        >
          确定
        </el-button>
      </span>
    </template>
  </el-dialog>
  <el-dialog
    v-model="passwordVisible"
    title="修改密码"
    width="576px"
    center
  >
    <el-form
      label-position="right"
      label-width="80px"
      :model="formLabelAlign"
      :rules="rules"
    >
      <el-form-item
        label="用户名"
        prop="userName"
      >
        <el-input
          v-model="formLabelAlign.userName"
          disabled
        />
      </el-form-item>
      <el-form-item
        label="当前密码"
        prop="currentPassword"
      >
        <el-input v-model="formLabelAlign.currentPassword" />
      </el-form-item>
      <el-form-item
        label="新密码"
        prop="newPassword"
      >
        <el-input v-model="formLabelAlign.newPassword" />
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button
          type="primary"
          @click="passwordVisible = false"
        >
          取消
        </el-button>
        <el-button
          type="primary"
          @click="passwordVisible = false"
        >
          确定
        </el-button>
      </span>
    </template>
  </el-dialog>
</template>

<style scoped lang=scss>
.menu-head-main-box {
  display: flex;
  justify-content: space-between;
  width: 100%;
  height: 100%;

  /* border: 1px solid red; */

  .left-box {
    display: flex;
    align-items: center;
    height: 100%;

    /* border: 1px solid green; */

    .logo-box {
      width: 260px;
      height: 70%;
      background-image: url("../../assets/imgs/logo.png");
      background-size: 100% 100%;

      /* border: 1px solid green; */
    }

    .breadcrumb-box {
      display: flex;
      align-items: flex-end;
      height: 100%;
      padding-bottom: 10px;
    }
  }

  .operate-btn-box {
    display: flex;
    align-items: center;
    width: 500px;
    height: 100%;

    /* border: 1px solid green; */

    >div {
      display: flex;
      align-items: center;
      width: 30px;
      height: 30px;

      /* border: 1px solid green; */

      &:hover {
        cursor: pointer;
      }
    }

    .select-theme,
    .refresh-btn {
      margin-left: 20px;
    }

    .sign-in,
    .sign-out {
      display: flex;
      justify-content: center;
      width: 70px;
      height: 40px;
      margin-left: 10px;
      color: #fff;
      border-radius: 5px;
    }

    .sign-in {
      background-color: #409eff;

      &:hover {
        background-color: #40a0ffaf;
      }
    }

    .sign-out {
      background-color: #ebb563;

      &:hover {
        background-color: #ebb563c0;
      }
    }

    .user-name {
      width: 70px;
      height: 40px;
      margin-left: 30px;
    }
  }
}

</style>
<style lang="scss">
.theme-box {
  /* border: 1px solid red; */

  >div {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 30px;
    color: rgb(92 93 95);
    font-size: 16px;

    &:hover {
      color: #409eff;
      background-color: #ebeff3;
      cursor: pointer;
    }
  }
}

.user-box {
  /* border: 1px solid red; */

  >div {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 80px;
    height: 40px;
    color: rgb(92 93 95);
    font-size: 16px;

    &:hover {
      color: #409eff;
      background-color: #ebeff3;
      cursor: pointer;
    }
  }
}

/* stylelint-disable-next-line selector-id-pattern */
#userInfoDialog {
  display: flex;
  justify-content: space-around;
  height: 60px;

  /* border: 1px solid red; */

  >div {
    display: flex;
    flex-wrap: wrap;
    align-items: space-between;
    width: 33%;

    /* border: 1px solid red; */

    >div {
      width: 100%;
      height: 40px;
      color: #000;
      font-size: 16px;
    }
  }
}

/* stylelint-disable-next-line selector-id-pattern */
#passwordDialog {
  color: #fff;
}
</style>